﻿#ifndef JSONPRASE_H
#define JSONPRASE_H

#include <QJsonDocument>
#include <QJsonObject>
#include <QList>
#include <QVariant>
#include <QHash>

enum ValueType
{
    NUM    =    0,
    OPTION,
    CHECK,
    STRING,
    LIST
};

typedef struct OptionCfg_t
{
    QString QStrName;
    ValueType enType;
    QJsonValue value;
    QJsonObject CfgObject;
    quint64 u64val;
    QHash<QString, quint64> Option;
    quint64 u64Min;
    quint64 u64Max;
    QString QStrhelp;
}OptionCfg;

typedef struct Variable_t
{
    QString QStrName;
    QJsonObject VarObject;
    QList<OptionCfg> CfgList;
}VariableObj;


typedef struct SubForm_t
{
    QString QStrName;
    QJsonObject SubFormObject;
    QList<VariableObj> VarList;
}SubForm;

typedef struct Form_t
{
    QString QStrName;
    QJsonObject FormObject;
    QList<SubForm> SubFormList;
}Form;


class JsonPrase:public QObject
{
public:
    JsonPrase(QByteArray jsonData);
    QList<Form>& FormGet(void);
    QList<SubForm>& SubFormGet(Form *pstForm);
    QList<VariableObj>& VarGet(SubForm *pstSubForm);
    QList<OptionCfg>& ConfigGet(VariableObj *pstVariable);
    void ConfigSet(OptionCfg *pstCfg, QVariant Value);
public slots:
    void SaveCfg(void);
private:
    QList<Form> FormList;
    QJsonObject gJsonObj;
    void JsonSubFormProc(Form *pstForm);
    void JsonVariableProc(SubForm *pstSubForm);
    void JsonOptionProc(VariableObj *pstVariable);
};

#endif // JSONPRASE_H
